<!-- user表单弹窗 -->
<form id="user-form" lay-filter="user-form" class="layui-form model-form">
    <input name="id" type="hidden"/>
    <div class="layui-form-item">
        <label class="layui-form-label">用户名</label>
        <div class="layui-input-block">
            <select name="userId" xm-select="userId" lay-verify="required">
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">招聘公司</label>
        <div class="layui-input-block">
            <select name="reId" xm-select="reId" lay-verify="required">
            </select>
        </div>
    </div>
    <div class="layui-form-item model-form-footer">
        <button class="layui-btn layui-btn-primary" ew-event="closeDialog" type="button">取消</button>
        <button class="layui-btn" lay-filter="user-form-submit" lay-submit>保存</button>
    </div>
</form>

<script>
    layui.use(['layer', 'admin', 'form', 'formSelects'], function () {
        var layer = layui.layer;
        var admin = layui.admin;
        var form = layui.form;
        var formSelects = layui.formSelects;

        form.render('radio');

        // 获取所有待业人员
        layer.load(2);
        admin.req('api-recruitment/recommend/unemployed', {}, function (data) {
            console.log(data);
            layer.closeAll('loading');
            if (0 == data.code) {
                // 渲染多选下拉框
                var roleSelectData = new Array();
                for (var i = 0; i < data.data.length; i++) {
                    roleSelectData.push({name: data.data[i].username, value: data.data[i].id});
                }
                formSelects.data('userId', 'local', {arr: roleSelectData});

                // 回显user数据
                var user = admin.getTempData('t_user');
                $('#user-form').attr('method', 'POST');
                // if (user) {
                //     form.val('user-form', user);
                //     $('#user-form').attr('method', 'POST');
                // }
            } else {
                layer.msg('失败', {icon: 2, time: 500});
            }
        }, 'GET');
        // 赋值在招职位信息
        // 回显user数据
        var tempData = admin.getTempData('t_user');
        layer.closeAll('loading');
        // 渲染多选下拉框
        let roleSelectData = new Array();
        roleSelectData.push({name: tempData.companyname, value: tempData.id + ':' + tempData.companyId});// 传：后是公司id

        formSelects.data('reId', 'local', {arr: roleSelectData});
        $('#user-form').attr('method', 'POST');
        // 表单提交事件
        form.on('submit(user-form-submit)', function (data) {
            console.log(data)
            layer.load(2);
            admin.req('api-recruitment/recommend/push', JSON.stringify(data.field), function (data) {
                layer.closeAll('loading');
                if (data.code == 0) {
                    layer.msg(data.msg, {icon: 1, time: 500});
                    admin.finishPopupCenter();
                } else {
                    layer.msg(data.msg, {icon: 2, time: 500});
                }
            }, $('#user-form').attr('method'));
            return false;
        });
    });
</script>